package nowcoder.offer;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 左旋转字符串
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-08-28 15:02
 */
public class LeftRotateString {

    public String solution(String str,int n){
        StringBuilder res = new StringBuilder();
        if (str == null || str.equals(""))
            return res.toString();
        LinkedList<Character> queue = new LinkedList<>();
        for (int i = 0; i < str.length(); i++) {
            queue.add(str.charAt(i));
        }
        for (int i = 0; i < n; i++) {
            Character c = queue.pop();
            queue.add(c);
        }
        for (Character c : queue) {
            res.append(c);
        }

        return res.toString();
    }

    public static void main(String[] args) {
        System.out.println(new LeftRotateString().solution("abcXYZdef", 3));
    }
}
